<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
<!--    <cpn></cpn>-->
    <cpn ref="aaa">

    </cpn>


</div>

<template id="a">
    <div>
        {{a}}
        <button @click="btnClick">btnClick</button>
        <cpnSon></cpnSon>

    </div>
</template>
<template id="aSon">
    <div>
        <button @click="btnClick">btnClickSon</button>
    </div>
</template>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>

<script>
    let cpnson = {
        template:"#aSon",
        data(){
            return {
                a:454
            }
        },
        methods: {
            btnClick(){
                console.log(this.$parent.a)
                console.log(this.$parent.$parent.message)
                /*
                * parent 是得到上一级父组件
                * root 访问得到的是根父组件
                * */
                console.log(this.$root.message)
            }
        }
    }
</script>
<script>
    let cpn = {
        template:"#a",
        data(){
            return {
                a:45444
            }
        },
        methods: {
            btnClick(){
                console.log(this.$parent)
            }
        },
        components: {
            cpnson
        }
    }
</script>


<script>
    const app = new Vue({
        el: "#app",
        data: {
            message: "message"
        },
        methods:{
        },
        components:{
            cpn,

        },
    })
</script>
</body>
</html>